#include "stdafx.h"
#include "EnumCallBack.h"

EnumCallBack::EnumCallBack(void)
{
}

EnumCallBack::~EnumCallBack(void)
{
}

BOOL CALLBACK EnumCallBack::EnumChildGetPosProc(HWND hwndChild, LPARAM lParam)
{
	CtrlMoveData* pCtrl = (CtrlMoveData*)lParam;

	CRect rcButton;
	pCtrl->pButtonChild->GetWindowRect(&rcButton);
	int sizey = pCtrl->sizey;
	BOOL bShow = pCtrl->bShow;

    // Retrieve the child-window identifier. Use it to set the 
    // position of the child window. 

    int idChild = ::GetWindowLong(hwndChild, GWL_ID);
	CWnd* pChildWnd = CWnd::FromHandle(hwndChild);

	if (::IsWindow(hwndChild)&&idChild!=0)
	{
		CRect rcChild;
		pChildWnd->GetWindowRect(&rcChild);

		CWnd* pParent = pChildWnd->GetParent();
		if (rcChild.top>=rcButton.bottom&&pParent == pCtrl->pMainDlg)
		{
			RECT CtrlRect;
			pChildWnd->GetWindowRect(&CtrlRect);
			pCtrl->pMainDlg->ScreenToClient(&CtrlRect);

			int dis = (bShow) ? sizey : -sizey;

			CtrlRect.bottom+=dis;
			CtrlRect.top+=dis;
			pChildWnd->MoveWindow(&CtrlRect,TRUE);
		}
	}

    return TRUE; 
}
